import * as HistoryManager from './HistoryManager';
import {Game} from './Game';
import {History} from './History';
import separate from '../patternSeparator';

separate('备忘录模式');

let state_1:string = getRandomNumber();
let state_2:string = getRandomNumber();
let state_3:string = getRandomNumber();

let game:Game = new Game();
// 改变游戏状态并保存
game.setState(state_1);
HistoryManager.addHistory(game.createHistory());
game.setState(state_2);
HistoryManager.addHistory(game.createHistory());
game.setState(state_3);
HistoryManager.addHistory(game.createHistory());

console.log('所有历史状态：' +　HistoryManager.getAllHistories().join(','));
console.log('Game当前状态：' + game.getState());

// 回退第一次
let history:History = HistoryManager.pop();
game.restore(history);
console.log('Game第一次回退之后的状态：' + game.getState());
console.log('历史状态指针：#'+HistoryManager.getPoint());

// 回退第二次
history = HistoryManager.pop();
game.restore(history);
console.log('Game第二次回退之后的状态：' + game.getState());
console.log('历史状态指针：#'+HistoryManager.getPoint());

function getRandomNumber():string{
  return (Math.random() * Math.random() * 1000).toFixed(0);
}